import 'package:freedom/page/mahjong/common/mahjong_context.dart';
import 'package:freedom/page/mahjong/common/message_content.dart';
import 'package:freedom/page/mahjong/message/abstract_action_message.dart';
import 'package:freedom/util/voice_message_sound.dart';

class DiceAction extends AbstractMessageActionHandler<MahjongMessage> {
  @override
  void doMessage(MahjongMessage message) {
    if (message.data == null) {
      return;
    }
    List<int> diceOT =
        message.data!.split(",").map((e) => int.parse(e)).toList();
    if (diceOT.length != 2) {
      return;
    }
    VoiceMessageSound().play("DICE", close: () {});
    MahjongContext.mahjongGameIndex.directionComponent!
        .addDice(diceOT[0], diceOT[1], message.swapCard, success: () {
      if (message.swapCard?.isNotEmpty ?? false) {
        MahjongContext().updateSwapCardIn(message.swapCard?.join(","));
      }
    });
  }
}
